package cn.stylefeng.guns.modular.shuheng.service;

import cn.stylefeng.guns.core.shiro.ShiroUser;
import cn.stylefeng.guns.modular.shuheng.entity.Content;
import cn.stylefeng.guns.modular.shuheng.entity.Data;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.stylefeng.guns.modular.shuheng.mapper.DataMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import cn.stylefeng.guns.core.common.page.LayuiPageFactory;

/**
 * <p>
 *  服务类
 * </p>
 *
 * @author zhengpp
 * @since 2021-03-07
 */
@Service
public class DataService extends ServiceImpl<DataMapper,Data> {
    public Page<Map<String,Object>> list(String condition, Long parentId,Integer year,Integer regionType,Long province,Long city,Long county) {
        Page page = LayuiPageFactory.defaultPage();
        return this.baseMapper.selectData(page,condition, parentId,year,regionType,province,city,county);
    }

    /**
     * 根据内容id查询
     * @param contentId
     * @param regionType
     * @return
     */
    public List<Data> listByContentId(Long contentId, String regionType) {
        return this.baseMapper.listByContentId(contentId,regionType);
    }

    public void deleteByYear(Integer year) {
        QueryWrapper<Data> wrapper = new QueryWrapper<>();
        wrapper.eq("data_year",year);
        this.baseMapper.delete(wrapper);
    }

    public List<Map<String,Object>> listByYearMonth(Integer year, ShiroUser user, Integer dataMonth) {
        return this.baseMapper.listByYearMonth(year,user.getUserLevel(),dataMonth,user.getProvince(),user.getCity(),user.getCounty());

    }

    public List<Map<String, Object>> countByLevelId(Integer year, ShiroUser user, int dataMonth) {
        return this.baseMapper.countByLevelId(year,user.getUserLevel(),dataMonth,user.getProvince(),user.getCity(),user.getCounty());
    }

    public List<Map<String, Object>> countByContentId(Integer year, ShiroUser user, int dataMonth) {
        return this.baseMapper.countByContentId(year,user.getUserLevel(),dataMonth,user.getProvince(),user.getCity(),user.getCounty());
    }

    public List<Data> listByLevelId(String levelId, String regionType) {
        return this.baseMapper.listByLevelId(levelId,regionType);
    }

    public Page<Map<String, Object>> listCityRank(Integer year, Integer rankType,String[] quarterArr) {
        Page page = LayuiPageFactory.defaultPage();
        return this.baseMapper.listCityRank(page,year,rankType,quarterArr);
    }

    public Page<Map<String, Object>> listCountyRank(Integer userLevel,Integer year, Long city, Integer rankType,String[] quarterArr) {
        Page page = LayuiPageFactory.defaultPage();
        return this.baseMapper.listCountyRank(page,userLevel,year,city,rankType,quarterArr);
    }

    public List<Map<String,Object>> excelCityRank(Integer year, Integer rankType,String[] quarterArr) {
        return this.baseMapper.excelCityRank(year,rankType,quarterArr);
    }

    public List<Map<String,Object>> excelCountyRank(Integer userLevel, Integer year, Long city, Integer rankType,String[] quarterArr) {
        return this.baseMapper.excelCountyRank(userLevel,year,city,rankType,quarterArr);
    }

    public Page<Map<String, Object>> listCityCompletion(Integer year, Integer rankType,String[] quarterArr) {
        Page page = LayuiPageFactory.defaultPage();
        return this.baseMapper.listCityCompletion(page,year,rankType,quarterArr);
    }

    public Page<Map<String, Object>> listCountyCompletion(Integer userLevel, Integer year, Long city, Integer rankType,String[] quarterArr) {
        Page page = LayuiPageFactory.defaultPage();
        return this.baseMapper.listCountyCompletion(page,userLevel,year,city,rankType,quarterArr);
    }

    public List<Map<String,Object>> listCityCompletionData(Integer year,String[] quarterArr) {
        return this.baseMapper.listCityCompletionData(year,quarterArr);
    }

    public List<Map<String,Object>> listCountyCompletionData(Integer year,String[] quarterArr,Integer userLevel,Long city) {
        return this.baseMapper.listCountyCompletionData(year,quarterArr,userLevel,city);
    }

    public List<Map<String,Object>> excelCityCompletion(Integer year, Integer rankType,String[] quarterArr) {
        return this.baseMapper.excelCityCompletion(year,rankType,quarterArr);
    }

    public List<Map<String,Object>> excelCountyCompletion(Integer userLevel, Integer year, Long city, Integer rankType,String[] quarterArr) {
        return this.baseMapper.excelCountyCompletion(userLevel,year,city,rankType,quarterArr);
    }

    public List<Map<String,Object>> listCityRankData(Integer year,String[] quarterArr) {
        return this.baseMapper.listCityRankData(year,quarterArr);
    }

    public List<Map<String,Object>> listCountyRankData(Integer year,String[] quarterArr,Integer userLevel,Long city) {
        return this.baseMapper.listCountyRankData(year,quarterArr,userLevel,city);
    }

    public List<Map<String,Object>> listCompletionByCity(Integer year,String[] quarterArr) {
        return this.baseMapper.listCompletionByCity(year,quarterArr);
    }
    public List<Map<String,Object>> listCompletionByCounty(Integer year,String[] quarterArr,Integer userLevel,Long city) {
        return this.baseMapper.listCompletionByCounty(year,quarterArr,userLevel,city);
    }

    public List<Map<String, Object>> mapByCity(Integer year,String[] quarterArr, Long regionId) {
        return this.baseMapper.mapByCity(year,quarterArr,regionId);
    }

    public List<Map<String, Object>> mapByCounty(Integer year,String[] quarterArr, Long regionId) {
        return this.baseMapper.mapByCounty(year,quarterArr,regionId);
    }

    public Page<Map<String,Object>> listCityProblem(Integer year, Integer rankType, String[] quarterArr) {
        Page page = LayuiPageFactory.defaultPage();
        return this.baseMapper.listCityProblem(page,year,rankType,quarterArr);
    }

    public Page<Map<String,Object>> listCountyProblem(Integer userLevel, Integer year, Long city, Integer rankType, String[] quarterArr) {
        Page page = LayuiPageFactory.defaultPage();
        return this.baseMapper.listCountyProblem(page,userLevel,year,city,rankType,quarterArr);
    }

    public List<Map<String,Object>> listExcelCityProblem(Integer year, Integer rankType, String[] quarterArr) {
        return this.baseMapper.listExcelCityProblem(year,rankType,quarterArr);
    }

    public List<Map<String,Object>> listExcelCountyProblem(Integer userLevel, Integer year, Long city, Integer rankType, String[] quarterArr) {
        return this.baseMapper.listExcelCountyProblem(userLevel,year,city,rankType,quarterArr);
    }

    public Page<Map<String,Object>> listCityProblemSearch(Integer year, Integer problemType, Long dataId,String dataName,String[] quarterArr) {
        Page page = LayuiPageFactory.defaultPage();
        return this.baseMapper.listCityProblemSearch(page,year,problemType,dataId,dataName,quarterArr);
    }

    public Page<Map<String,Object>> listCountyProblemSearch(Integer userLevel, Integer year, Long city, Integer problemType, Long dataId,String dataName,String[] quarterArr) {
        Page page = LayuiPageFactory.defaultPage();
        return this.baseMapper.listCountyProblemSearch(page,userLevel,year,city,problemType,dataId,dataName,quarterArr);
    }

    public List<Map<String,Object>> listByYearBeforeMonth(Integer year, ShiroUser user, Integer dataMonth) {
        return this.baseMapper.listByYearBeforeMonth(year,user.getUserLevel(),dataMonth,user.getProvince(),user.getCity(),user.getCounty());
    }
}
